package com.csweimei.rentmanagementtreasure.tenant.ui.act.house;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.content.Intent;
import android.os.Bundle;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityAddHouseFloowBinding;
import com.csweimei.rentmanagementtreasure.http.entity.CustomerBean;
import com.csweimei.rentmanagementtreasure.http.entity.HouseInfoDetailBean;
import com.csweimei.rentmanagementtreasure.tenant.viewModel.AddHouseFVM;

import me.goldze.mvvmhabit.base.BaseActivity;

public class AddHouseFollowActivity extends BaseActivity<ActivityAddHouseFloowBinding, AddHouseFVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_add_house_floow;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    HouseInfoDetailBean bean;
    String type;
    @Override
    public void initParam() {
        super.initParam();
        bean = (HouseInfoDetailBean) getIntent().getSerializableExtra(AppConfig.BUNDLE_KEY);
        type = getIntent().getStringExtra("type");
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        viewModel.houseInfo.set(bean);
        viewModel.setImg(binding.img);
        viewModel.FollowType.set(type);
    }

    @Override
    public AddHouseFVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(AddHouseFVM.class);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 10087){
            CustomerBean.DataDTO customerBean = (CustomerBean.DataDTO) data.getSerializableExtra("data");
            viewModel.customer.set(customerBean.getName());
            viewModel.customid.set(customerBean.getId()+"");
        }
    }
}